// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import axios from 'axios'
import 'element-ui/lib/theme-chalk/index.css';
import VeeValidate, { Validator } from 'vee-validate'
import zh_CN from 'vee-validate/dist/locale/zh_CN';
Validator.localize('zh_CN', zh_CN);//vee 本地化
Vue.use(VeeValidate);

Vue.use(ElementUI)
Vue.config.productionTip = false
Vue.prototype.$http= axios

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
const token=sessionStorage.getItem('demo-token');
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
router.beforeEach((to,from,next)=>{	
	if(to.path=='/'){
		if(token!='null'&&token!=null){
			next('/todolist')
		}
		next();
	}else if(to.path=="/signin"){
		next();
	}
	else{
		if(token!='null'&&token!=null){

			next()
		}else{
			next('/')
		}
	}
})